#ifndef MODBUS_H
#define MODBUS_H

#include <QObject>
#include <QDebug>
#include <QTcpSocket>
#include <QTimer>
#include "snap7.h"
#include "common.h"

#define PLC_IP "168.168.168.100"
#define PLC_RACK_NUMBER 0 //PLC机架号
#define PLC_SLOT_NUMBER 1 //PLC插槽号
#define PLC_READ_CYCLE 100 //plc读取周期，ms
#define RECONNECT_INTERVAL 10000 //重连间隔

class Plc : public QObject
{
    Q_OBJECT
public:
    explicit Plc(QObject *parent = nullptr);
    ~Plc();

signals:
    void connected();

private:
    //连接参数
    TS7Client _s7client;
    QTimer *_reconnect_timer;
    QTimer *_rw_timer;
    int _reconnect_times;
    bool _connect_flag;

    bool _recv_vision = true;

    //初始化
    void Init();
    void ConnectPrepare();

private slots:
    void RWData();

public slots:
    void ConnectToPlc();
    void PauseReqVision(const bool& res);
};

#endif // MODBUS_H
